package com.clps.threadPool.test01;

import java.math.BigDecimal;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class demo01 {
    public static void main(String[] args) {
        String input = "Hello and 78.";
        Pattern pattern = Pattern.compile("\\d+");
        Matcher matcher = pattern.matcher(input);

        while (matcher.find()) {
            System.out.println("找到的数字: " + matcher.group());
        }

        System.out.println("=====================================");


        // 假设你想替换的数字是动态的，存储在变量中
        int replacementNumber = 789;

        // 原始字符串，其中"{number}"作为占位符
        String originalString = "Hello 123, this is a test 456.";

        // 使用String.format方法替换占位符
        // 注意这里假设你确切知道数字的位置并用占位符表示，实际情况可能需要更复杂的逻辑来定位和替换数字
        String replacedString = originalString.replace("123", String.valueOf(replacementNumber));
        replacedString = replacedString.replace("456", String.valueOf(replacementNumber)); // 假设有两个位置的数字需要替换

        System.out.println(replacedString);  // 输出: Hello 789, this is a test 789.

        System.out.println("=====================================");

        BigDecimal original = new BigDecimal("10.00");
        BigDecimal stripped = original.stripTrailingZeros();

        // 输出结果将是 10
        System.out.println(stripped);
        System.out.println("=====================================");



        BigDecimal original1 = new BigDecimal("123.00000");

        // 使用stripTrailingZeros()去除末尾的0
        BigDecimal stripped1 = original1.stripTrailingZeros();
        System.out.println(stripped1);
    }
}
